package com.str;

public class ReverseString0201_541 {
    public String reverseStr(String s, int k) {

        StringBuilder str = new StringBuilder(s);

        int i,left,right;
        for (i = 0; i < str.length(); i=i+2*k) {
            left = i;
            right = i+k-1;
            if(left+k > str.length()) right = str.length()-1;
            while (left < right){
                char temp = str.charAt(right);
                str.setCharAt(right,str.charAt(left));
                str.setCharAt(left,temp);
                left++;right--;
            }
        }

        return new String(str);
    }
}
